<?php

use yii\helpers\Url;
use yii\helpers\Html;
use kartik\grid\GridView;
use kartik\export\ExportMenu;

$gridColumns = [
    //复选框列
    ['class' => 'kartik\grid\CheckboxColumn'],
    [
        //设置字段显示标题
        'label' => 'ID',
        //字段名
        'attribute' => 'id',
        //格式化
        'format' => 'raw',
        //设置单元格样式
        'headerOptions' => [
            'style' => 'width:120px;',
        ],
    ],
    [
        'label' => '姓名',
        'attribute' => 'name',
        'format' => 'raw',
    ],
    [
        'label' => 'Code',
        'attribute' => 'code',
        'format' => 'raw',
    ],
    [
        'label' => '状态',
        'attribute' => 't_status',
        'format' => 'raw',
        'filter' => [ 'ok' => 'ok', 'hold' => 'hold' ],
    ],
];

?>

<div id="page-wrapper">
    <div class="row">
        <div class="col-lg-12">
            <button class="btn btn-primary" id="showSelBtn">显示我选中的</button>
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <?php echo ExportMenu::widget([
                'dataProvider' => $provider,
                'columns' => $gridColumns,
                'encoding' => 'gb2312',
                'dropdownOptions' => [
                    'label' => '导出',
                    'class' => 'btn btn-default'
                ],
                'exportConfig' => [
                    ExportMenu::FORMAT_TEXT => false,
                    ExportMenu::FORMAT_PDF => false,
                    ExportMenu::FORMAT_EXCEL_X => FALSE,
                ],
                'columnSelectorOptions'=>[
                    'label' => '选择字段',
                ],
                'filename' => '试用申请列表_'.date('Y-m-d'),
                'selectedColumns'=> [1], // 导出不选中#和操作栏
                'hiddenColumns'=>[0], // 隐藏#和操作栏
            ])?>
            <?php echo GridView::widget([
                //设置GridView的ID
                'id' => 'myUserGridView',
                //设置数据提供器
                'dataProvider' => $provider,
                //设置筛选模型
                'filterModel' => $model,
                'columns' => $gridColumns,
                'export' => false,
            ]); ?>
        </div>
    </div>
</div>

<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script type="text/javascript">
    $("#showSelBtn").on("click", function () {

        var keys = $("#myUserGridView").yiiGridView('getSelectedRows');

        alert(keys);

    });

</script>